package cn.zijian.wechat.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import cn.zijian.wechat.R;
import cn.zijian.wechat.adapter.models.TabItem;
import cn.zijian.wechat.fragment.ContactFragment;
import cn.zijian.wechat.fragment.MessageFragment;
import cn.zijian.wechat.fragment.ProfileFragment;

/**
 * Created by Administrator on 2017/12/13.
 */

public class PagerAdapter  extends FragmentPagerAdapter
{

    public static TabItem[] tabItems = {
         new TabItem("微信", R.drawable.message_normal, R.drawable.message_pressed),
         new TabItem("联系人", R.drawable.contact_normal, R.drawable.contact_pressed),
         new TabItem("我的", R.drawable.profile_normal, R.drawable.profile_pressed)
    };

    public PagerAdapter(FragmentManager fm)
    {
        super(fm);
    }

    @Override
    public Fragment getItem(int position)
    {
        Fragment returnFragment = null;
        switch (position)
        {
            case 1: returnFragment = new MessageFragment();
                break;
            case 2:  returnFragment = new ContactFragment();
                break;
            case 3:  returnFragment = new ProfileFragment();
                break;
            default:  returnFragment = new MessageFragment();
        }
        return returnFragment;
    }

    @Override
    public CharSequence getPageTitle(int position)
    {
        return tabItems[position].getText();
    }

    @Override
    public int getCount()
    {
        return tabItems.length;
    }
}
